<template>
	<view>
		<cu-custom bgColor="bg-gradual-green" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">修改密码</block>
		</cu-custom>
		
		<view class="cu-form-group">
			<view class="title">新密码
				<view class="cu-tag badge" style="position: absolute;left: -17upx;top: 20upx;"></view>
			</view>
			<input style="text-align: right;" type="number" password	v-model="pwd" placeholder="请输入新密码" name="input"></input>
		</view>
		
		<view class="cu-form-group">
			<view class="title">确认新密码
				<view class="cu-tag badge" style="position: absolute;left: -17upx;top: 20upx;"></view>
			</view>
			<input style="text-align: right;" type="number" password v-model="sure_pwd" placeholder="请确认新密码" name="input"></input>
		</view>
		
		<button class="cu-btn bg-gradual-green margin-tb-sm lg" style="width: 700upx;margin: 25upx;" @click="sure">确认修改</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				res:[],
				openid:'',
				pwd:'',
				sure_pwd: '',
			};
		},
		onLoad:function(){
			uni.showLoading()
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data
					console.log(this.openid)
					this.setAjax()
				},
				fail: () => {
					uni.navigateTo({
						url: '/pagesA/login/login'
					});
				}
			});
		},
		methods:{
			setAjax(){
				uni.hideLoading()
			},
			sure(){
				var o = this
				if (this.pwd == "") {
					uni.showToast({
						title: '请输入新密码',
						icon:"none"
					});
					return
				}else if (this.pwd != this.sure_pwd) {
					this.pwd = ""
					this.sure_pwd = ""
					uni.showToast({
						title: '两次密码输入不一致',
						icon:"none"
					});
					return
				} else {
				var data = {
						'pwd': this.pwd,
						'userId': this.openid,
					}
					console.log(JSON.stringify(data))
					uni.request({
						url: 'https://jxjsservice.jxfit.cn/coach/user/updateSysUser',
						method: 'POST',
						data: data,
						header:{'Content-Type':'application/x-www-form-urlencoded'},
						success: res => {
							if ( res.data.result == 200 ) {
								uni.showToast({
									title: '修改成功',
									icon: 'none'
								})
								setTimeout(()=>{
									uni.reLaunch({
										url: '/pagesA/login/login',
									})
								},700)
							} else {
								uni.showToast({
									title: res.data.msg,
									icon: 'none'
								})
							}
						},
						fail: () => {},
						complete: () => {}
					});
				}
			},
			jump(e){
				uni.navigateTo({
					url: e.currentTarget.dataset.src
				});
			},
		}
	}
</script>

<style>
</style>
